Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
GET statements
You use a form of the
GETstatement to change the current position within the record set that theOPEN QUERYstatement defines. You’ve already seen these statements on the button triggers in theh-CustOrderWin1.wprocedure you built in Chapter 4, " Introducing the OpenEdge AppBuilder." This is the syntax for theGETstatement:
The query must be open before you can use a
GETstatement. If the query involves a join, Progress populates all the buffers used in the query on eachGETstatement. As noted earlier, a record can remain current through multipleGETstatements if a second table in the query has multiple records matching the record for the first table. This would be the case for a Customer and its Orders, for example. A series ofGET NEXTstatements leaves the same Customer record in its buffer as long as there is another matching Order record to read into the Order buffer.When you first open a query, it is positioned in effect before the first record in the result set. Either a
GET FIRSTor aGET NEXTstatement positions to the first record in the result set.If you execute a
GET NEXTstatement when the query is already positioned on the last record, then the query is positioned effectively beyond the end of the result set. AGET PREVstatement then repositions to the last record in the result set. Likewise, aGET PREVstatement executed when already on the first record results in the query being positioned before the first record, and aGET FIRSTorGET NEXTstatement repositions to the first record. When the query is repositioned off the beginning or off the end of the result set, no error results. You can use theAVAILABLEfunction that you’re already familiar with to check whether you have positioned beyond the result set. For example, this code opens a query and cycles through all the records in its result set, simply counting them as it goes:
Figure 10–2 shows the result.
Figure 10–2: Result of GET statement example
![]()
The
GET FIRSTstatement is needed to make a record available before theIF AVAILABLEstatement is first encountered. Otherwise, theAVAILABLEtest would fail before the code ever entered the loop.Note also that the
AVAILABLEfunction must take a buffer name as its argument, not the name of the query. If the query involves an outer join, then you should be careful about which buffer you use in theAVAILABLEfunction. If you name a buffer that could be empty because of an outer join (such as an empty Order buffer for a Customer with no Orders), then your loop could terminate prematurely. On the other hand, you might want your application logic to test specifically for the presence of one buffer or another in order to take special action when one of the buffers has no record.Using the QUERY-OFF-END function
There is a built-in Progress function that you can use for the same purpose as the
AVAILABLEstatement:
QUERY-OFF-ENDis a logical function that returnstrueif the query is positioned either before the first result set row or after the last row, andfalseif it is positioned directly on any row in the result set. Thequery-nameparameter must be either a quoted literal string with the name of the query or a variable name that has been set to the name of the query. In this way, you can use the statement programmatically to test potentially multiple different active queries in your procedure.For example, here is the same procedure used above, this time with the
QUERY-OFF-ENDfunction in place ofAVAILABLE:
The difference between
QUERY-OFF-ENDandAVAILABLEis simply thatAVAILABLErequires a buffer name as a parameter, whereasQUERY-OFF-ENDrequires a query name. If you use theAVAILABLEfunction with the name of the first buffer in the query, it is equivalent to usingQUERY-OFF-ENDwith the query name. Just for stylistic reasons, it is more appropriate to use theQUERY-OFF-ENDfunction in most cases, since it is the position of the query and not the presence of a record in a particular buffer that you’re really interested in. By contrast, if you really want to test for the presence of a record, especially when your query does an outer join that might not always retrieve a record into every buffer, then use theAVAILABLEfunction.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |